﻿// ***********************************************************************
// Assembly         : OSS.ModelViewer
// Author           : tian_
// Created          : 05-16-2018
//
// Last Modified By : tian_
// Last Modified On : 04-28-2018
// ***********************************************************************
// <copyright file="OsgTianTengTestCmd.cs" company="">
//     Copyright ©  2018
// </copyright>
// <summary></summary>
// ***********************************************************************
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Osg;
using OSS.ModelViewer.Utility;
using ZFGK.Actions;
using ZFGK.Addins;
using ZFGK.IO;
using ZFGK.OSG.UI;
using ZFGK.Utility;
using ZFGK.WinForms.Utility;

namespace OSS.ModelViewer.Commands.TestCmds
{
    /// <summary>
    /// Class OsgTianTengTestCmd.
    /// </summary>
    /// <seealso cref="ZFGK.Addins.IExtendCommand" />
    public class OsgTianTengTestCmd : IExtendCommand
    {
        /// <summary>
        /// Executes the specified command data.
        /// </summary>
        /// <param name="cmdData">The command data.</param>
        /// <param name="message">The message.</param>
        /// <returns>CmdResult.</returns>
        public CmdResult Execute(ExtendCmdData cmdData, ref string message)
        {
            var viewForm = cmdData.ViewForm as IViewForm;
            var osgView = viewForm.View as IOsgViewCtrl;

            string fileListPath;
            if (DialogUtil.OpenText(out fileListPath))
            {
                var lines = File.ReadAllLines(fileListPath);
                foreach (var line in lines)
                {
                    osgView.OsgObj.AddOrReplaceModel("Models", OsgDB._.readNodeFile(line));
                }
            }

            //NewMethod3();
            //NewMethod2(osgView);
            return CmdResult.Succeed;
        }

        private static void NewMethod3()
        {
            var vec1 = new Vec3d(1, 1, 1);
            var vec2 = vec1.DeepClone();
            vec2.x = 1;

            var c1 = new class1();
            c1.pt1.x = 2;
            var c2 = c1.DeepClone();
            c2.pt2.x = 3;
            c2.val1 = 2;
            c2.val2 = "new";
            c2.verts.First().x = 1000;
            c2.vals[0] = 100;

            MessageBox.Show(c1.ToString() + "\r\n" + c2.ToString());
        }

        private static void NewMethod2(IOsgViewCtrl osgView)
        {
//             var actionUtility = osgView.ActionUtility;
//             int retint;
//             var finish = actionUtility.getKeyWord("选择关键字:", new[] {"T", "E", "S"}, new[] {"T", "E", "S"}, out retint);
//             if (finish)
//             {
//                 MessageBox.Show(retint.ToString());
//             }
// 
//             ZfTreeListManager.TreeList.BeginUpdate();
//             var rootNode = ZfTreeListManager.TreeList.Nodes.FirstNode;
//             foreach (var child in osgView.RootNode.GetChildren())
//             {
//                 ZfTreeListManager.TreeList.AppendNode(new object[]
//                 {
//                     child.name + "[" + child.className + "]"
//                 }, rootNode, child);
//             }
// 
//             ZfTreeListManager.TreeList.EndUpdate();
        }

        public class class1
        {
            public Vec3d pt1 = new Vec3d(1, 1, 1);
            public Vec3f pt2 = new Vec3f(1, 1, 1);
            public int val1 = 10;
            public string val2 = "20";

            public List<Vec3d> verts = new List<Vec3d>(new[] { new Vec3d(1, 2, 3), new Vec3d(10, 20, 30) });
            public List<int> vals = new List<int>(new[] { 1, 2, 3 });

            public override string ToString()
            {
                return pt1.ToString() + " " + pt2.ToString() + " " + val1 + " " + val2;
            }
        }

        private static void NewMethod1()
        {
            Vec3Array vertexArray = new Vec3Array();
            vertexArray.push_back(new Vec3f(-1.0f, 0.0f, -1.0f));
            vertexArray.push_back(new Vec3f(-0.25f, 0.0f, -1.0f));
            vertexArray.push_back(new Vec3f(-0.25f, 0.0f, -0.25f));
            vertexArray.push_back(new Vec3f(1.0f, 0.0f, -1.0f));
            vertexArray.push_back(new Vec3f(1.0f, 0.0f, 1.0f));
            vertexArray.push_back(new Vec3f(-1.0f, 0.0f, 1.0f));
        }

        /// <summary>
        /// News the method.
        /// </summary>
        private static void NewMethod()
        {
            string path = @"D:\工作资料\智帆高科\配电网三维平台\Source\DistributionNetwork3dPlatform\ZFGK.OSG\Utility\GL.cs";
            var lines = File.ReadAllLines(path);

            List<string> newLines = new List<string>();
            foreach (var line in lines)
            {
                string newLine = line;
                if (newLine.StartsWith("//"))
                {
                    newLine += ";";
                }

                newLines.Add(newLine);
            }

            File.WriteAllText(path, string.Join("\r\n", newLines), Encoding.Default);
        }
    }
}
